/*
 * @Author: 李无敌
 * @Date: 2025-07-30 12:02:10
 * @LastEditors: 李无敌
 * @LastEditTime: 2025-08-12 16:34:44
 * @FilePath: \nest-base\src\modules\user-log\controllers\user-log.controller.ts
 */
import { Controller, Get, Query } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { UserLogService } from '../services/user-log.service';
import { UserActionType } from '../entities/user-log.entity';
import { PaginationDto } from '../../../common/dto/pagination.dto';
import { ApiResponseDto } from '../../../common/dto/response.dto';
import { ApiName } from '../../../common/decorators/api-name.decorator';
import { QueryUserLogDto } from '../dto/query-user-log.dto';

@ApiTags('系统日志')
@ApiBearerAuth()
@Controller('user-logs')
export class UserLogController {
  constructor(private readonly userLogService: UserLogService) {}

  @Get('page')
  @ApiOperation({ 
    summary: '分页获取用户行为日志列表',
    description: '支持按用户ID、操作类型、接口名称等条件筛选，支持分页查询'
  })
  @ApiName('分页获取用户行为日志列表')
  async getUserLogs(
    @Query() query: QueryUserLogDto,
  ): Promise<ApiResponseDto<any>> {
    const { userId, actionType, apiName, ...paginationDto } = query;
    
    const [logs, total] = await this.userLogService.findUserLogsWithFilters(
      { userId, actionType, apiName },
      paginationDto
    );
    
    return ApiResponseDto.success({
      data: logs,
      total,
      page: paginationDto.page,
      pageSize: paginationDto.pageSize,
      totalPages: Math.ceil(total / paginationDto.pageSize),
      hasNext: paginationDto.page < Math.ceil(total / paginationDto.pageSize),
      hasPrev: paginationDto.page > 1,
    }, '获取用户日志成功');
  }
} 